import BH3MysApi from "./mysApi.js"
import base from "./base.js"
import mysCfg from "./mysCfg.js"

const regionMap = {
  android01: "安卓官服",
  bb01: "哔哩哔哩",
  hun01: "渠道1服",
  hun02: "渠道2服",
  pc01: "全平台（桌面）服",
  ios01: "iOS服",
  yyb01: "应用宝服",
}

export default class role extends base {
  constructor(e) {
    super(e)
    this.model = "role"
  }

  async getData(e) {
    let { uid, ck, game_biz, region } = await mysCfg.othergame(e)
    let mysApi = new BH3MysApi(uid, ck, { game: "bh3" }, region, game_biz)
    let device_fp = await mysApi.getData("getFp")
    let headers = { "x-rpc-device_fp": device_fp?.data?.device_fp }
    let res = await mysApi.getBH3ApiData("index", { headers })
    let abyss = await mysApi.getBH3ApiData("newAbyssReport", { headers })
    let data = res.data
    let abyssData = abyss.data.reports[0]
    const gridData = this.formatGridData(data, abyssData)
    return {
      ...this.screenData,
      ...data.role,
      grid: gridData.line,
      uid: uid,
      server_name: regionMap[data.role.region],
    }
  }

  formatGridData(originalData, abyssData) {
    const { stats } = originalData
    return {
      line: [
        [
          { num: stats.active_day_number, lable: "活跃天数" },
          { num: stats.armor_number, lable: "装甲数" },
          { num: abyssData.cup_number, lable: "成就数量" },
          { num: stats.battle_field_ranking_percentage + "%", lable: "记忆战场" },
          { num: stats.god_war_max_challenge_score, lable: "乐土成绩" },
        ],
        [
          {
            num: stats.explore_score,
            lable: "第二部箱庭",
            extra: stats.explore_score_sum,
          },
          { num: stats.sss_armor_number, lable: "SSS装甲" },
          { num: stats.weapon_number, lable: "收藏武器数" },
          { num: stats.stigmata_number, lable: "收藏圣痕数" },
          { num: stats.suit_number, lable: "服装数" },
        ],
      ],
    }
  }
}
